import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { rules } from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import { getPeriodTree } from '/@/api/common/api';
import { renderDict } from '../../../components/utils/index';
import dayjs from 'dayjs';
import { useUserStore } from '/@/store/modules/user';
const userStore = useUserStore();
//列表数据
export const columns: BasicColumn[] = [
  {
    title: '主键',
    align: 'center',
    dataIndex: 'id',
    ifShow: false,
  },
  {
    title: '考核周期',
    align: 'center',
    dataIndex: 'periodCode',
    // customRender: ({ text }) => {
    //   return text?.slice(0, 4) + '年' + text?.slice(-1) + '月';
    // },
  },
  {
    title: '上级部门',
    dataIndex: 'parentOrgName',
    width: 200,
    align: 'center',
  },
  {
    title: '班组编码',
    align: 'center',
    dataIndex: 'orgCode',
    ifShow: false,
  },
  {
    title: '班组名称',
    align: 'center',
    dataIndex: 'orgName',
  },
  {
    title: '绩效兼职',
    align: 'center',
    dataIndex: 'pluraNameList',
  },
  {
    title: '绩效经理人',
    align: 'center',
    dataIndex: 'psnName',
  },
  {
    title: '提交状态',
    align: 'center',
    dataIndex: 'status',
    customRender: ({ text }) => {
      return render.renderDict(text, 'epm_team_resultType');
    },
  },
]

//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    field: 'periodCode',
    label: '考核周期',
    component: 'ApiTreeSelect',
    componentProps: {
      api: getPeriodTree,
      // options: monthOptionsList,
      fieldNames: {
        children: 'child',
        label: 'periodName',
        value: 'periodCode',
      },
    },
    colProps: { span: 8 },
    defaultValue: dayjs().format('YYYYMM'),
  },
  {
    label: '所属部门',
    field: 'orgCode',
    required: false,
    component: 'Select',
    componentProps: () => {
      return {
        sync: false,
        titleKey: 'orgName',
        rowKey: 'orgCode',
        multiple: true, //多选
        maxTagCount: 3,
        isSuper: true,
        params: {
          status: 0,
        },
      };
    },
  },
  {
    field: 'status',
    label: '提交状态',
    component: 'Select',
    colProps: { span: 6 },
  },
];
//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '主键',
    field: 'id',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请输入主键!' }];
    },
  },
  {
    label: '考核周期',
    field: 'periodCode',
    component: 'Input',
  },
  {
    label: '组织编码',
    field: 'orgCode',
    component: 'Input',
  },
  {
    label: '组织名称',
    field: 'orgName',
    component: 'Input',
  },
  {
    label: '姓名',
    field: 'psnName',
    component: 'Input',
  },
  {
    label: '工号',
    field: 'psnNum',
    component: 'Input',
  },
  {
    label: '人员类型',
    field: 'personType',
    component: 'Input',
  },
  {
    label: '岗位编码',
    field: 'posCode',
    component: 'Input',
  },
  {
    label: '岗位名称',
    field: 'posName',
    component: 'Input',
  },
  {
    label: '重点工作内容',
    field: 'keyContent',
    component: 'InputTextArea',
    componentProps: {
      maxlength: 50,
      showCount: true,
    },
  },
  {
    label: '考核得分',
    field: 'finalScore',
    component: 'InputNumber',
  },
  {
    label: '评分说明',
    field: 'finalScoreDesc',
    component: 'InputTextArea',
    componentProps: {
      maxlength: 50,
      showCount: true,
    },
  },
  {
    label: '状态',
    field: 'status',
    component: 'InputNumber',
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请输入状态!' }];
    },
  },
  {
    label: '考核单位',
    field: 'suitUnit',
    component: 'Input',
  },
  {
    label: '描述',
    field: 'remark',
    component: 'InputTextArea',
    componentProps: {
      maxlength: 50,
      showCount: true,
    },
  },
  {
    label: '排序',
    field: 'displayOrder',
    component: 'InputNumber',
  },
  {
    label: '创建日期',
    field: 'sysCreateDate',
    component: 'DatePicker',
  },
  {
    label: '创建人',
    field: 'sysCreatorId',
    component: 'Input',
  },
  {
    label: '修改日期',
    field: 'sysUpdateDate',
    component: 'DatePicker',
  },
  {
    label: '修改人',
    field: 'sysUpdatorId',
    component: 'Input',
  },
  // TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
];

/**
 * 流程表单调用这个方法获取formSchema
 * @param param
 */
export function getBpmFormSchema(_formData): FormSchema[] {
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}
